import java.util.ArrayList;
import java.util.Scanner;


public class Main2 {

    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;
        Integer a;
        while (true) {
            n = in.nextInt();
            ArrayListIntegerStack arrayIntegerStack = new ArrayListIntegerStack(n);
            for (int i = 0; i < n; i++) {
                a = in.nextInt();
                a= arrayIntegerStack.push(a);
                System.out.println(a);
            }
            System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
            System.out.println(arrayIntegerStack.getArrayList());
            n = in.nextInt();
            for (int i = 0; i < n; i++) {
                System.out.println(arrayIntegerStack.pop());
            }
            System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
            System.out.println(arrayIntegerStack.getArrayList());
        }
    }

}

interface IntegerStack {

    public Integer push(Integer item);

    public Integer pop();

    public Integer peek();

    public boolean empty();

    public int size();
}

class ArrayListIntegerStack implements IntegerStack {

    private ArrayList<Integer> List;
    private final int n;

    public ArrayListIntegerStack(int n) {
        List = new ArrayList<>();
        this.n = n;
    }

    public Integer push(Integer item) {
        if (item == null) {
            return null;
        }
        if (List.size() >= n) {
            return null;
        }
        List.add(item);
        return item;
    }

    public Integer pop() {
        if (List.size() == 0) {
            return null;
        }
        Integer a;
        a=List.get(List.size()-1);
        List.remove(List.size()-1);
        return a;
    }

    public Integer peek() {
        if (List.size() == 0) {
            return null;
        }
        return List.get(List.size()-1);
    }

    public boolean empty() {
        return List.size() == 0;
    }

    public int size() {
        return List.size();
    }

    public ArrayList<Integer> getArrayList(){
    	return List;
    }
    public String toString(){
    	return List.toString();
    }
}